package net.funwoo.pandago.util;

import android.content.Context;
import android.widget.Toast;

import net.funwoo.pandago.R;

import retrofit.client.Response;

/**
 * Created by Bob Peng on 2015/5/7.
 */
public class HttpUtils {
    public static String getErrorCodeMessge(int code) {
        switch (code) {
            case 400:
                return "错误请求";
            case 403:
                return "服务器拒绝请求";
            case 404:
                return "服务器找不到请求的网页";
            case 408:
                return "服务器等候请求时发生超时";
            case 500:
                return "服务器遇到错误，无法完成请求";
            default:
                return "服务器发生错误，请稍后再试";
        }
    }

    public static void onRequestFailed(Context context, Response response) {
        if (response != null) {
            Toast.makeText(context, HttpUtils.getErrorCodeMessge(response.getStatus()),
                    Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(context, R.string.msg_no_network, Toast.LENGTH_SHORT).show();
        }
    }
}
